package br.rnp.linkcrawler;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.SortedSet;

public class LinkCrawlerApp {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		URL start = null;
		String filter;
		try {
			start = new URL(args[0]);
		} catch (ArrayIndexOutOfBoundsException e) {
			throw new IllegalArgumentException("Forneça um link inicial.");
		} catch (MalformedURLException e1) {
			throw new IllegalArgumentException(
					"Link inicial não é uma URL válida.");
		}
		try {
			filter = args[1];
		} catch (ArrayIndexOutOfBoundsException e) {
			filter = "";
		}
		SortedSet<URL> links = Crawler.crawlFrom(start).under(filter).getLinks();
		
		for (URL url : links) {
			System.out.println(url);
		}
	}

}
